package com.itheima.web.controller;

import com.itheima.vo.MovementVo;
import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/management")
public class UserController {

    @Autowired
    private UserManager userManager;

    // 分页查询
    @GetMapping("/manage/users")
    public ResponseEntity findUserInfoByPage(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                             @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return userManager.findUserInfoByPage(pageNum, pageSize);
    }

    // 用户详情
    @GetMapping("/manage/users/{userId}")
    public ResponseEntity findUserInfoById(@PathVariable Long userId) {
        return userManager.findUserInfoById(userId);
    }

    /**
     * Author：fxq
     * 根据userId查询
     * @param id
     * @return
     */
    @GetMapping("/manage/findById")
    public ResponseEntity findById(Long id) {
        // 调用manager
        return userManager.findById(id);
    }

    // 动态列表
    @GetMapping("/manage/messages")
    public ResponseEntity findMovementVoByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "uid", required = false) Long userId,
            Integer state) {
        return userManager.findMovementVoByPage(userId, state, pageNum, pageSize);
    }

    // 动态详情
    @GetMapping("/manage/messages/{publishId}")
    public ResponseEntity findMovementVoById(@PathVariable String publishId){
        return userManager.findMovementVoById(publishId);
    }

    // 动态评论分页
    @GetMapping("/manage/messages/comments")
    public ResponseEntity findCommentVoByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize,
            @RequestParam("messageID") String publishId){
        return userManager.findCommentVoByPage(pageNum,pageSize,publishId);
    }

    //后台动态审核通过
    @PostMapping("/manage/messages/pass")
    public ResponseEntity passMovement(@RequestBody String[] publishId) {
        List<MovementVo> vos = userManager.passMovement(publishId);
        return ResponseEntity.ok(vos);
    }

    //后台动态审核拒绝
    @PostMapping("/manage/messages/reject")
    public ResponseEntity rejectMovement(@RequestBody String[] publishId) {
        return ResponseEntity.ok("操作成功");
    }
}
